package main

import (
	"bytes"
	"crypto/md5"
	"crypto/sha1"
	"encoding/binary"
	"fmt"
)

func GetHashCode(key string, hashType int) int32 {
	var result []byte

	switch hashType {
	case 1:
		Md5Inst := md5.New()
		Md5Inst.Write([]byte(key))
		result = Md5Inst.Sum([]byte(""))
	case 2:
		Sha1Inst := sha1.New()
		Sha1Inst.Write([]byte(key))
		result = Sha1Inst.Sum([]byte(""))
	}
	binBuf := bytes.NewBuffer(result)
	var x int32
	binary.Read(binBuf, binary.BigEndian, &x)

	return x
}

func main() {
	key := "HelloWorld1"
	fmt.Println(GetHashCode(key, 1))
}
